package com.boarsoft.boar.sequence.snowflake;

import java.io.Serializable;

/**
 * 雪花算法可置项
 * 
 * @author user
 *
 */
public class SnowflakeConfig implements Serializable {
	public static final long serialVersionUID = -8673776094887654627L;

	private String id;

	/**
	 * 服务器第一次上线时间点, 设置后不允许修改<br>
	 * 默认是2018/9/29日，从此时开始计算，可以用到2089年
	 */
	private int sinceYear = 2018;
	/**
	 * worker id 的bit数，11 bits 最多支持2048个节点
	 */
	private int workerIdBits = 11;
	/**
	 * 序列号，支持单节点最高每毫秒的最大ID数，11 bits 最多2048个
	 */
	private int sequenceBits = 11;
	/**
	 * 最大容忍时间, 单位毫秒, 即如果时钟只是回拨了该变量指定的时间, 那么等待相应的时间即可; 考虑到sequence服务的高性能, 这个值不易过大
	 */
	private int maxBackward = 3;

	/**
	 * 工作机器ID(0~31) snowflake算法给workerId预留了10位，即workId的取值范围为[0, 1023]，
	 * 事实上实际生产环境不大可能需要部署1024个分布式ID服务， 所以：将workerId取值范围缩小为[0, 511]，[512, 1023]
	 * 这个范围的workerId当做备用workerId。workId为0的备用workerId是512，
	 * workId为1的备用workerId是513，以此类推
	 */
	public int workerId;

	public int clockId;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public int getSinceYear() {
		return sinceYear;
	}

	public void setSinceYear(int sinceYear) {
		this.sinceYear = sinceYear;
	}

	public int getWorkerIdBits() {
		return workerIdBits;
	}

	public void setWorkerIdBits(int workerIdBits) {
		this.workerIdBits = workerIdBits;
	}

	public int getSequenceBits() {
		return sequenceBits;
	}

	public void setSequenceBits(int sequenceBits) {
		this.sequenceBits = sequenceBits;
	}

	public int getMaxBackward() {
		return maxBackward;
	}

	public void setMaxBackward(int maxBackward) {
		this.maxBackward = maxBackward;
	}

	public int getWorkerId() {
		return workerId;
	}

	public void setWorkerId(int workerId) {
		this.workerId = workerId;
	}

	public int getClockId() {
		return clockId;
	}

	public void setClockId(int clockId) {
		this.clockId = clockId;
	}
}